<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use HasFactory;

    protected $table = 'comment';

    protected $fillable = ['reply_id', 'author_id', 'comment', 'ip', 'status', 'blog_id'];

    protected $hidden = ['ip'];

    public function author () {
        return $this->belongsTo(User::class, 'author_id', 'id');
    }

    public function replies () {
        return $this->hasMany(Comment::class, 'reply_id', 'id')->with(['replies', 'author']);
    }

    public function reply () {
        return $this->belongsTo(Comment::class, 'reply_id', 'id')->with(['author']);
    }
}
